from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-08-21 14:02:40.465661
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 21, Aug, 2022
Time: 14:02:47
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.1800
Nobs: 755.000 HQIC: -50.5190
Log likelihood: 9599.45 FPE: 9.28116e-23
AIC: -50.7315 Det(Omega_mle): 8.24464e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.296039 0.055111 5.372 0.000
L1.Burgenland 0.107686 0.036620 2.941 0.003
L1.Kärnten -0.106844 0.019424 -5.500 0.000
L1.Niederösterreich 0.208709 0.076424 2.731 0.006
L1.Oberösterreich 0.107253 0.074355 1.442 0.149
L1.Salzburg 0.254121 0.039143 6.492 0.000
L1.Steiermark 0.037107 0.051049 0.727 0.467
L1.Tirol 0.108328 0.041355 2.619 0.009
L1.Vorarlberg -0.060183 0.035525 -1.694 0.090
L1.Wien 0.052379 0.066007 0.794 0.427
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.063000 0.114739 0.549 0.583
L1.Burgenland -0.033550 0.076241 -0.440 0.660
L1.Kärnten 0.046986 0.040440 1.162 0.245
L1.Niederösterreich -0.175664 0.159109 -1.104 0.270
L1.Oberösterreich 0.400528 0.154802 2.587 0.010
L1.Salzburg 0.288533 0.081493 3.541 0.000
L1.Steiermark 0.106145 0.106282 0.999 0.318
L1.Tirol 0.314084 0.086099 3.648 0.000
L1.Vorarlberg 0.026344 0.073962 0.356 0.722
L1.Wien -0.028758 0.137423 -0.209 0.834
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189901 0.028308 6.708 0.000
L1.Burgenland 0.089833 0.018810 4.776 0.000
L1.Kärnten -0.008841 0.009977 -0.886 0.376
L1.Niederösterreich 0.260521 0.039256 6.637 0.000
L1.Oberösterreich 0.134742 0.038193 3.528 0.000
L1.Salzburg 0.045756 0.020106 2.276 0.023
L1.Steiermark 0.018277 0.026222 0.697 0.486
L1.Tirol 0.093756 0.021242 4.414 0.000
L1.Vorarlberg 0.058487 0.018248 3.205 0.001
L1.Wien 0.118726 0.033905 3.502 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.107461 0.028805 3.731 0.000
L1.Burgenland 0.046342 0.019141 2.421 0.015
L1.Kärnten -0.014390 0.010153 -1.417 0.156
L1.Niederösterreich 0.192041 0.039945 4.808 0.000
L1.Oberösterreich 0.292773 0.038864 7.533 0.000
L1.Salzburg 0.111204 0.020459 5.435 0.000
L1.Steiermark 0.102547 0.026682 3.843 0.000
L1.Tirol 0.108901 0.021615 5.038 0.000
L1.Vorarlberg 0.069937 0.018568 3.766 0.000
L1.Wien -0.017582 0.034500 -0.510 0.610
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.128174 0.052243 2.453 0.014
L1.Burgenland -0.051007 0.034715 -1.469 0.142
L1.Kärnten -0.040617 0.018413 -2.206 0.027
L1.Niederösterreich 0.171418 0.072446 2.366 0.018
L1.Oberösterreich 0.140158 0.070485 1.988 0.047
L1.Salzburg 0.288437 0.037106 7.773 0.000
L1.Steiermark 0.033518 0.048393 0.693 0.489
L1.Tirol 0.162436 0.039203 4.143 0.000
L1.Vorarlberg 0.100749 0.033677 2.992 0.003
L1.Wien 0.068754 0.062572 1.099 0.272
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.056634 0.041675 1.359 0.174
L1.Burgenland 0.040295 0.027692 1.455 0.146
L1.Kärnten 0.050302 0.014689 3.425 0.001
L1.Niederösterreich 0.220877 0.057792 3.822 0.000
L1.Oberösterreich 0.286155 0.056227 5.089 0.000
L1.Salzburg 0.045134 0.029600 1.525 0.127
L1.Steiermark -0.001346 0.038604 -0.035 0.972
L1.Tirol 0.147330 0.031273 4.711 0.000
L1.Vorarlberg 0.072666 0.026864 2.705 0.007
L1.Wien 0.082778 0.049915 1.658 0.097
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.177720 0.049785 3.570 0.000
L1.Burgenland -0.003992 0.033081 -0.121 0.904
L1.Kärnten -0.062092 0.017547 -3.539 0.000
L1.Niederösterreich -0.080303 0.069038 -1.163 0.245
L1.Oberösterreich 0.193855 0.067169 2.886 0.004
L1.Salzburg 0.057122 0.035360 1.615 0.106
L1.Steiermark 0.231625 0.046116 5.023 0.000
L1.Tirol 0.496051 0.037359 13.278 0.000
L1.Vorarlberg 0.047013 0.032092 1.465 0.143
L1.Wien -0.054706 0.059628 -0.917 0.359
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.165539 0.057346 2.887 0.004
L1.Burgenland -0.010879 0.038105 -0.285 0.775
L1.Kärnten 0.067118 0.020212 3.321 0.001
L1.Niederösterreich 0.205892 0.079522 2.589 0.010
L1.Oberösterreich -0.068231 0.077369 -0.882 0.378
L1.Salzburg 0.210688 0.040729 5.173 0.000
L1.Steiermark 0.116634 0.053119 2.196 0.028
L1.Tirol 0.070987 0.043032 1.650 0.099
L1.Vorarlberg 0.121837 0.036966 3.296 0.001
L1.Wien 0.122079 0.068683 1.777 0.075
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.360150 0.032950 10.930 0.000
L1.Burgenland 0.007188 0.021895 0.328 0.743
L1.Kärnten -0.023609 0.011613 -2.033 0.042
L1.Niederösterreich 0.214479 0.045692 4.694 0.000
L1.Oberösterreich 0.194381 0.044455 4.372 0.000
L1.Salzburg 0.044782 0.023403 1.914 0.056
L1.Steiermark -0.015674 0.030521 -0.514 0.608
L1.Tirol 0.105740 0.024725 4.277 0.000
L1.Vorarlberg 0.072871 0.021240 3.431 0.001
L1.Wien 0.041511 0.039464 1.052 0.293
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.040220 0.145092 0.192770 0.154769 0.122692 0.108665 0.065171 0.221361
Kärnten 0.040220 1.000000 -0.005435 0.133168 0.039895 0.095414 0.431574 -0.053077 0.098702
Niederösterreich 0.145092 -0.005435 1.000000 0.337161 0.144748 0.297987 0.101598 0.181571 0.317702
Oberösterreich 0.192770 0.133168 0.337161 1.000000 0.227204 0.330661 0.173272 0.167027 0.263516
Salzburg 0.154769 0.039895 0.144748 0.227204 1.000000 0.145521 0.117230 0.145851 0.126473
Steiermark 0.122692 0.095414 0.297987 0.330661 0.145521 1.000000 0.149329 0.137109 0.076491
Tirol 0.108665 0.431574 0.101598 0.173272 0.117230 0.149329 1.000000 0.113567 0.146976
Vorarlberg 0.065171 -0.053077 0.181571 0.167027 0.145851 0.137109 0.113567 1.000000 0.003640
Wien 0.221361 0.098702 0.317702 0.263516 0.126473 0.076491 0.146976 0.003640 1.000000